import time
from selenium import webdriver
from selenium.webdriver.common.by import By
# TODO 导入select 类
from selenium.webdriver.support.ui import Select

# TODO 第二种 select类方式
# 打开浏览器访问网址
driver = webdriver.Chrome()
driver.get('https://sahitest.com/demo/selectTest.htm')

# TODO 创建select对象，参数是要操作的select标签
s1 = driver.find_element(By.ID,'s1')
select = Select(s1)

# TODO 选择option
# 通过索引选取option,索引从0开始
time.sleep(2)
select.select_by_index(1)

# 通过value值选取option
time.sleep(2)
select.select_by_value('49')

# 通过文本选取option
time.sleep(2)
select.select_by_visible_text('Mail')

# 关闭浏览器
time.sleep(2)
driver.quit()